package com.sj.purchase.modules.cost.views.stock;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.jeecgframework.poi.excel.annotation.Excel;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.Objects;

/**
 * Created by yangrd on 2017/9/14
 **/
public class SkuStockReportVO {

    @Excel(name = "sku编码", width = 20)
    private String skuNO;//sku编码

    @Excel(name = "sku名称", width = 20)
    private String skuName;//sku名称

    @Excel(name = "期初库存", width = 20)
    private Long beginStock;//期初库存

    @Excel(name = "期末库存", width = 20)
    private Long endStock;//期末库存

    @Excel(name = "采购入库", width = 20)
    private Long inPurchaseStock;//采购入库

    @Excel(name = "退货入库", width = 20)
    private Long inReturnStock;//退货入库

    @Excel(name = "销售出库", width = 20)
    private Long outSalesStock;//销售出库

    @Excel(name = "采购退货", width = 20)
    private Long outProcurementReturns;

    @Excel(name = "其他出库", width = 20)
    private Long outOtherStock;//其他出库

    @Excel(name = "库存调整数量", width = 20)
    private Long adjustStock;//库存调整数量

    @Excel(name = "期末库存成本", width = 20)
    private Double endStockCost;//期末库存成本

    @Excel(name = "日期段", width = 30)
    private String dateSegment;//日期段

    private static final String FORMAT_YYYY_MM_DD = "yyyy-MM-dd";

    {
        beginStock = 0L;
        endStock = 0L;
        inPurchaseStock = 0L;
        inReturnStock = 0L;
        outSalesStock = 0L;
        outOtherStock = 0L;
        adjustStock = 0L;
    }

    public String getSkuNO() {
        return skuNO;
    }

    public SkuStockReportVO setSkuNO(String skuNO) {
        this.skuNO = skuNO;
        return this;
    }

    public Double getEndStockCost() {
        return endStockCost;
    }

    public SkuStockReportVO setEndStockCost(Double endStockCost) {
        this.endStockCost = endStockCost;
        return this;
    }

    public String getSkuName() {
        return skuName;
    }

    public SkuStockReportVO setSkuName(String skuName) {
        this.skuName = skuName;
        return this;
    }

    public static String getFormatYyyyMmDd() {
        return FORMAT_YYYY_MM_DD;
    }

    public Long getBeginStock() {
        return beginStock;
    }

    public SkuStockReportVO setBeginStock(Long beginStock) {
        this.beginStock = beginStock;
        return this;
    }

    public Long getEndStock() {
        return endStock;
    }

    public SkuStockReportVO setEndStock(Long endStock) {
        this.endStock = endStock;
        return this;
    }

    public Long getInPurchaseStock() {
        return inPurchaseStock;
    }

    public SkuStockReportVO setInPurchaseStock(Long inPurchaseStock) {
        this.inPurchaseStock = inPurchaseStock;
        return this;
    }

    public Long getInReturnStock() {
        return inReturnStock;
    }

    public SkuStockReportVO setInReturnStock(Long inReturnStock) {
        this.inReturnStock = inReturnStock;
        return this;
    }

    public Long getOutSalesStock() {
        return outSalesStock;
    }

    public SkuStockReportVO setOutSalesStock(Long outSalesStock) {
        this.outSalesStock = outSalesStock;
        return this;
    }

    public Long getOutProcurementReturns() {
        return outProcurementReturns;
    }

    public SkuStockReportVO setOutProcurementReturns(Long outProcurementReturns) {
        this.outProcurementReturns = outProcurementReturns;
        return this;
    }

    public Long getOutOtherStock() {
        return outOtherStock;
    }

    public SkuStockReportVO setOutOtherStock(Long outOtherStock) {
        this.outOtherStock = outOtherStock;
        return this;
    }

    public Long getAdjustStock() {
        return adjustStock;
    }

    public SkuStockReportVO setAdjustStock(Long adjustStock) {
        this.adjustStock = adjustStock;
        return this;
    }

    public String getDateSegment() {
        return dateSegment;
    }

    public SkuStockReportVO setDateSegment(String dateSegment) {
        this.dateSegment = dateSegment;
        return this;
    }

    /**
     * 计算期末库存
     *
     * @return
     */
    public SkuStockReportVO calculatorEndStock() {
        this.endStock = this.beginStock + (this.inReturnStock + this.inPurchaseStock) - (+this.outProcurementReturns + this.outOtherStock + this.outSalesStock) + this.adjustStock;
        return this;
    }

    /**
     * 计算期末库存成本
     *
     * @return
     */
    public SkuStockReportVO endStockCost(Double costPriceService) {
        DecimalFormat df = new DecimalFormat("#.00");
        this.endStockCost = Double.valueOf(df.format(endStock*costPriceService));
        return this;
    }

    /**
     * 设置日期段
     *
     * @param start
     * @param end
     */
    public SkuStockReportVO setDateSegment(Date start, Date end) {
        this.setDateSegment(getDateSegment(start, end));
        return this;
    }

    /**
     * 格式化日期段 减少调用次数
     *
     * @param start
     * @param end
     * @return yyyy-MM-dd--yyyy-MM-dd
     */
    public static String getDateSegment(Date start, Date end) {
        Objects.requireNonNull(start);
        Objects.requireNonNull(end);
        return DateFormatUtils.format(start, FORMAT_YYYY_MM_DD) + "至" + DateFormatUtils.format(end, FORMAT_YYYY_MM_DD);
    }

}
